<template>
  <el-container>
    <el-main>
      <el-row>
        <el-col :span="12">
          <el-button type="primary" @click="increment">increment</el-button>
          <el-button type="text" @click="showDoneTodos">showDoneTodos</el-button>
          <el-button type="info" @click="findTodoById">findTodoById</el-button>
        </el-col>
        <el-col :span="12">
          <el-input v-model="count"></el-input>
        </el-col>
      </el-row>
      <el-row class="top10">
        <el-col :span="12">
          <el-button type="danger" @click="dispatchIncrement">dispatchIncrement</el-button>
          <el-button type="warning" @click="dispatchIncrementAsync">dispatchIncrementAsync</el-button>
          <el-button type="success" @click="goOAuth">OAuth2.0</el-button>
          <el-button @click="getUserInfo">获取用户信息</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-button @click="selectEnterpriseContact">选人</el-button>
          <el-button @click="checkIsSupportSoterAuthentication">检测识别</el-button>
          <el-button @click="checkIsSoterEnrolledInDevice">查询生物信息是否录入</el-button>
          <el-button @click="startSoterAuthentication">信息认证</el-button>
          <el-button @click="bioassayAuthentication">人脸识别</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          用户Id:{{user.UserId}}
        </el-col>
      </el-row>
      <el-row>
        <el-col >
          设备Id:{{user.DeviceId}}
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          用户类型:<span v-if="user.usertype == 2">超级管理员</span>
          <span v-if="user.usertype == 4">分级管理员</span>
          <span v-if="user.usertype == 5">普通成员</span>
        </el-col>
      </el-row>
    </el-main>
  </el-container>
</template>

<script>
  import UserService from '../../service/UserService'
  export default {
    name: "vuex-demo",
    components: {},
    props: {},
    computed: {
      count() {
        return this.$store.state.count;
      }
    },
    data() {
      return {
        user:{}
      }
    },
    methods: {
      increment() {
        this.$store.commit('increment');
      },
      showDoneTodos() {
        console.log(this.$store.getters.doneTodos)
      },
      findTodoById() {
        console.log(this.$store.getters.getTodoById(1));
      },
      dispatchIncrement() {
        this.$store.dispatch('increment')
      },
      dispatchIncrementAsync() {
        this.$store.dispatch('incrementAsync').then((resp) => {
          console.log(resp);
        });
      },
      showUserId() {
        console.log(this.$store.state.user.userId);
        (function () {
          console.log('IIFE')
        }());
      },
      goOAuth() {
        window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wldfc8d2cef1&redirect_uri=http://49.234.54.41:9988/wx-web&response_type=code&scope=snsapi_userinfo&agentid=1000151&state=STATE#wechat_redirect";
      },
      selectEnterpriseContact() {
        this.$wx.invoke("selectEnterpriseContact", {
            "fromDepartmentId": -1,// 必填，表示打开的通讯录从指定的部门开始展示，-1表示自己所在部门开始, 0表示从最上层开始
            "mode": "multi",// 必填，选择模式，single表示单选，multi表示多选
            "type": ["department", "user"]// 必填，选择限制类型，指定department、user中的一个或者多个
          }, function (res) {
            console.log(res);
            if (res.err_msg == "selectEnterpriseContact:ok") {
              if (typeof res.result == 'string') {
                res.result = JSON.parse(res.result) //由于目前各个终端尚未完全兼容，需要开发者额外判断result类型以保证在各个终端的兼容性
              }
              console.log(res.result);
            }
          }
        );
      },
      checkIsSupportSoterAuthentication() {
        this.$wx.invoke("checkIsSupportSoterAuthentication", {}, function (res) {
          if (res.err_msg != "checkIsSupportSoterAuthentication:ok") {
            //错误处理
            console.log(res.err_msg);
          } else {
            // res.supportMode = [] 不具备任何被SOTER支持的生物识别方式
            // res.supportMode = ['fingerPrint'] 只支持指纹识别
            // res.supportMode = ['fingerPrint', 'facial'] 支持指纹识别和人脸识别
          }
        });
      },
      checkIsSoterEnrolledInDevice() {
        this.$wx.invoke("checkIsSoterEnrolledInDevice", { checkAuthMode: "fingerPrint" }, function (res) {
          if (res.err_msg != "checkIsSoterEnrolledInDevice:ok") {
            //错误处理
            console.log(res.err_msg)
          } else {
            console.log(res.isEnrolled)
          }
        });
      },
      startSoterAuthentication() {
        this.$wx.invoke("startSoterAuthentication", {
          requestAuthModes: ["facial", "fingerPrint"],
          challenge: "test_challenge",
          authContent: "请按指纹识别"
        }, function (res) {
          if (res.err_msg != "startSoterAuthentication:ok") {
            //错误处理
            console.log(res.err_msg)
          } else {
            console.log(res.authMode);// 认证方式
            console.log(res);//用户填写的挑战因子
          }
        });
      },
      bioassayAuthentication() {
        this.$wx.invoke('bioassayAuthentication', {
          name: '徐维', // 姓名
          idcard: '420123198206132012' // 身份证号
        }, function (res) {
          if (res.err_msg == "bioassayAuthentication:ok") {
            console.log(res);
            var code = res.code; //检测成功
          } else {
            console.log(res);
            //错误处理
          }
        });
      },
      getUserInfo(){
        UserService.getUserByCode().then(res=>{
          this.user = res.data;
        });
      }
    }
  }
</script>

<style scoped>
  .top10 {
    padding-top: 10px;
  }
</style>
